package com.controller.dataSource;

import com.model.pojo.annotation.CheckToken;
import com.model.po.Databases;
import com.model.pojo.RepEntity;
import com.model.pojo.TestPage;
import com.model.vo.configVo.DatabasesInfo;
import com.server.dataSource.DataBasesService;
import com.server.dataSource.ImplementSqlService;
import com.config.RoleInterceptor.Auth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/DataBase")
public class DataBasesController {
    @Autowired
    DataBasesService dataBasesService;
    @Autowired
    ImplementSqlService implementSqlService;
    /*
   数据库
   保存数据库配置
   */
    @CheckToken
    @Auth(user = "admin")
    @RequestMapping("/inputDatabases")
    public RepEntity inputDatabases(@RequestHeader String token, @RequestBody DatabasesInfo body){
        return dataBasesService.inputDatabases(body);
    }

    /*
    查看数据库配置列表
     */
    @CheckToken
    @Auth(user = "admin")
    @RequestMapping("/getDatabases")
    public RepEntity getDatabases(@RequestHeader String token, @RequestBody TestPage body){
        return dataBasesService.getListDatabases(body);
    }

    /*
    删除数据库配置
     */
    @CheckToken
    @Auth(user = "admin")
    @RequestMapping("/delDatabases")
    public RepEntity delDatabases(@RequestHeader String token,@RequestBody List<Integer> body){
        return dataBasesService.delDatabases(body);
    }

    /*
    更新数据库配置
     */
    @CheckToken
    @Auth(user = "admin")
    @RequestMapping("/updatabases")
    public RepEntity updatabases(@RequestHeader String token,@RequestBody DatabasesInfo databasesInfo){
        return dataBasesService.updatabases(databasesInfo);
    }

    /*
    查看列
     */
    @CheckToken
    @RequestMapping("/getColumnData")
    public RepEntity getColumnData(@RequestHeader String token,@RequestBody int body){
        return dataBasesService.getColumnData(body);
    }

    /*
    通过图表Id查看列数据
     */
    @CheckToken
    @RequestMapping("/getColumnByChartId")
    public RepEntity getColumnByChartId(@RequestHeader String token,@RequestBody int body){
        return dataBasesService.getColumnByChartId(body);
    }


    /*
    测试数据库连接
     */
    @CheckToken
    @Auth(user = "admin")
    @RequestMapping("/testConnect")
    public RepEntity testConnect(@RequestHeader String token,@RequestBody Databases body){
        return implementSqlService.connectTest(body);
    }
}
